<?php

namespace app\exception;

use support\exception\Handler;
use Throwable;
use Webman\Http\Request;
use Webman\Http\Response;

class CommonHandler extends Handler
{
    public function report(Throwable $exception)
    {
        parent::report($exception);
    }

    public function render(Request $request, Throwable $exception): Response
    {
        if ($exception instanceof ApiException) {
            return new \support\Response(200, ['content-type' => 'application/json'], json_encode([
                'code' => $exception->getCode(),
                'msg' => $exception->getMessage(),
                'data' => []
            ]));
        }

        return parent::render($request, $exception);
    }
}